package org.feerepository.client.components;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;


public class IndexedLabel extends Composite 
{
	private Label text = new Label();
	private Image removeIcon ;
	private Grid content1 = new Grid(1,2);
	private int index1;
	
	private SearchPanel ownerPanel;
	


	public IndexedLabel(String text, int index)
	{
		super();
		this.index1 = index;
		this.text.setText(text);
		content1.setCellPadding(2);
		content1.setCellSpacing(0);
		CellFormatter formater = content1.getCellFormatter();
		formater.setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
		formater.setAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
		content1.setWidget(0, 0, this.text);
		MyImages images = GWT.create(MyImages.class);
		removeIcon = images.closeIcon().createImage();
		
		removeIcon.addClickListener(new ClickListener()
		{

			public void onClick(Widget sender) 
			{
				ownerPanel.removeItem(index1);
				
			}
			
		});
		content1.setWidget(0, 1, removeIcon);
		initWidget(content1);
	}
	
	public int getIndex() {
		return index1;
	}

	public void setIndex(int index) {
		this.index1 = index;
	}

	public SearchPanel getOwnerPanel() {
		return ownerPanel;
	}

	public void setOwnerPanel(SearchPanel ownerPanel) {
		this.ownerPanel = ownerPanel;
	}

}
